<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Math::Big - routines (cos,sin,primes,hailstone,euler,fibbonaci etc) with big numbers - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Math-Big - MetaCPAN" href="https://metacpan.org/dist/Math-Big/releases.rss" />
        <link rel="canonical" href="./Math::Big.html" />
        <meta name="description" content="routines (cos,sin,primes,hailstone,euler,fibbonaci etc) with big numbers" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Math::Big" />
<meta name="twitter:title"       content="Math::Big" />
<meta name="twitter:description" content="routines (cos,sin,primes,hailstone,euler,fibbonaci etc) with big numbers" />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Math::Big.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Math-Big was released.">
      <span class="relatize">29 Sep 2021 18:48:01 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Math-Big">Math-Big</a>
  </li>
  <li>
    Module version: 1.16
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Math-Big/source/lib/Math/Big.pm">Source</a>
    (<a href="https://metacpan.org/dist/Math-Big/source/lib/Math/Big.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Math-Big/source/lib/Math">Browse</a>
    (<a href="https://metacpan.org/dist/Math-Big/source/lib/Math?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Math-Big/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Math-Big/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/pjacklam/p5-Math-Big">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="https://rt.cpan.org/Public/Dist/Display.html?Name=Math-Big">Issues</a>
      (1)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Math-Big+1.16" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Big.html?oncpan=1&amp;distmat=1&amp;version=1.16&amp;grade=2" style="color: #090">785</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Big.html?oncpan=1&amp;distmat=1&amp;version=1.16&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/M/Math-Big.html?oncpan=1&amp;distmat=1&amp;version=1.16&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/PJACKLAM/Math-Big-1.16">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Math-Big who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 1
      </div>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpancover.com/latest/Math-Big-1.16/index.html">80.25% Coverage </a>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.6.2
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Math-Big/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/P/PJ/PJACKLAM/Math-Big-1.16.tar.gz">
      Download (<span itemprop="fileSize">29.04KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FPJACKLAM%2FMath-Big-1.16%2Flib%2FMath%2FBig.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Math-Big/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Math-Big/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Math-Big">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Math-Big">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Math/Big.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="PJACKLAM/Math-Big-1.16"
>1.16
  (PJACKLAM on 2021-09-29)</option>
<option
  
  value="PJACKLAM/Math-Big-1.15"
>1.15
  (PJACKLAM on 2021-07-14)</option>
<option
  
  value="TELS/Math-Big-1.12"
>1.12
  (TELS on 2007-04-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="PJACKLAM/Math-Big-1.14"
>1.14
  (PJACKLAM on 2016-12-04)</option>
<option
  
  value="PJACKLAM/Math-Big-1.13"
>1.13
  (PJACKLAM on 2016-04-26)</option>
<option
  
  value="TELS/Math-Big-1.11"
>1.11
  (TELS on 2005-01-02)</option>
<option
  
  value="TELS/Math-Big-1.10"
>1.10
  (TELS on 2004-08-15)</option>
<option
  
  value="TELS/Math-Big-1.09"
>1.09
  (TELS on 2003-12-11)</option>
<option
  
  value="TELS/Math-Big-1.08"
>1.08
  (TELS on 2002-08-13)</option>
<option
  
  value="TELS/Math-Big-1.07"
>1.07
  (TELS on 2002-03-27)</option>
<option
  
  value="TELS/Math-Big-1.06"
>1.06
  (TELS on 2001-11-08)</option>
<option
  
  value="TELS/Math-Big-1.05"
>1.05
  (TELS on 2001-07-09)</option>
<option
  
  value="TELS/Math-Big-1.04"
>1.04
  (TELS on 2001-06-15)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/PJACKLAM/Math-Big-1.16/diff/' + encodeURIComponent(this.value) + '/lib/Math/Big.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="PJACKLAM/Math-Big-1.16"
>1.16
  (PJACKLAM on 2021-09-29)</option>
<option
  
  value="PJACKLAM/Math-Big-1.15"
>1.15
  (PJACKLAM on 2021-07-14)</option>
<option
  
  value="TELS/Math-Big-1.12"
>1.12
  (TELS on 2007-04-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="PJACKLAM/Math-Big-1.14"
>1.14
  (PJACKLAM on 2016-12-04)</option>
<option
  
  value="PJACKLAM/Math-Big-1.13"
>1.13
  (PJACKLAM on 2016-04-26)</option>
<option
  
  value="TELS/Math-Big-1.11"
>1.11
  (TELS on 2005-01-02)</option>
<option
  
  value="TELS/Math-Big-1.10"
>1.10
  (TELS on 2004-08-15)</option>
<option
  
  value="TELS/Math-Big-1.09"
>1.09
  (TELS on 2003-12-11)</option>
<option
  
  value="TELS/Math-Big-1.08"
>1.08
  (TELS on 2002-08-13)</option>
<option
  
  value="TELS/Math-Big-1.07"
>1.07
  (TELS on 2002-03-27)</option>
<option
  
  value="TELS/Math-Big-1.06"
>1.06
  (TELS on 2001-11-08)</option>
<option
  
  value="TELS/Math-Big-1.05"
>1.05
  (TELS on 2001-07-09)</option>
<option
  
  value="TELS/Math-Big-1.04"
>1.04
  (TELS on 2001-06-15)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><a href="https://metacpan.org/pod/Carp" title="Carp" class="ellipsis">Carp</a></li>
  <li><a href="https://metacpan.org/pod/Math::BigInt" title="Math::BigInt" class="ellipsis">Math::BigInt</a></li>
  <li><i class="ttip" title="dynamic_config enabled">and possibly others</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Math::Big/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Math%3A%3ABig">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Math-Big">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/PJACKLAM/Math-Big-1.16/view/lib/Math/Big.pm">This version</a>
    </li>
    <li>
      <a href="./Math::Big.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/DGKONTOP"><img src="https://www.gravatar.com/avatar/1f2db1aed2ab9bee2feee0b9823c61d6?d=identicon&amp;s=20" title="DGKONTOP" alt="DGKONTOP"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Math-Big/plussers">1 PAUSE user</a>
</div>
</div>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/PJACKLAM" class="author-name">Peter John Acklam</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Math/Big.pm&#39;" class="">
<option
  selected
  value="PJACKLAM/Math-Big-1.16"
>1.16
  (PJACKLAM on 2021-09-29)</option>
<option
  
  value="PJACKLAM/Math-Big-1.15"
>1.15
  (PJACKLAM on 2021-07-14)</option>
<option
  
  value="TELS/Math-Big-1.12"
>1.12
  (TELS on 2007-04-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="PJACKLAM/Math-Big-1.14"
>1.14
  (PJACKLAM on 2016-12-04)</option>
<option
  
  value="PJACKLAM/Math-Big-1.13"
>1.13
  (PJACKLAM on 2016-04-26)</option>
<option
  
  value="TELS/Math-Big-1.11"
>1.11
  (TELS on 2005-01-02)</option>
<option
  
  value="TELS/Math-Big-1.10"
>1.10
  (TELS on 2004-08-15)</option>
<option
  
  value="TELS/Math-Big-1.09"
>1.09
  (TELS on 2003-12-11)</option>
<option
  
  value="TELS/Math-Big-1.08"
>1.08
  (TELS on 2002-08-13)</option>
<option
  
  value="TELS/Math-Big-1.07"
>1.07
  (TELS on 2002-03-27)</option>
<option
  
  value="TELS/Math-Big-1.06"
>1.06
  (TELS on 2001-11-08)</option>
<option
  
  value="TELS/Math-Big-1.05"
>1.05
  (TELS on 2001-07-09)</option>
<option
  
  value="TELS/Math-Big-1.04"
>1.04
  (TELS on 2001-06-15)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Math-Big">Math-Big-1.16</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage one &#10;
          • 2 direct dependents &#10;          • 2 total dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#7ea3f2" />
      <rect x="5"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Math-Big-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Math-Big-1.16">
    <input type="hidden" name="author" value="PJACKLAM">
    <input type="hidden" name="distribution" value="Math-Big">
    <button type="submit" class="favorite highlight"><span>1</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Math::Big.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>1</span> ++</a>
</div>
   / <span>Math::Big</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Math::Big.html#NAME">NAME</a></li>
  <li><a href="./Math::Big.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Math::Big.html#REQUIRES">REQUIRES</a></li>
  <li><a href="./Math::Big.html#EXPORTS">EXPORTS</a></li>
  <li><a href="./Math::Big.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Math::Big.html#FUNCTIONS">FUNCTIONS</a></li>
  <li><a href="./Math::Big.html#CAVEATS">CAVEATS</a></li>
  <li><a href="./Math::Big.html#BUGS">BUGS</a></li>
  <li><a href="./Math::Big.html#SUPPORT">SUPPORT</a></li>
  <li><a href="./Math::Big.html#LICENSE">LICENSE</a></li>
  <li><a href="./Math::Big.html#AUTHOR">AUTHOR</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Math::Big - routines (cos,sin,primes,hailstone,euler,fibbonaci etc) with big numbers</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code>    use Math::Big qw/primes fibonacci hailstone factors wheel
      cos sin tan euler bernoulli arctan arcsin pi/;

    @primes     = primes(100);          # first 100 primes
    $count      = primes(100);          # number of primes &lt;= 100
    @fib        = fibonacci (100);      # first 100 fibonacci numbers
    $fib_1000   = fibonacci (1000);     # 1000th fibonacci number
    $hailstone  = hailstone (1000);     # length of sequence
    @hailstone  = hailstone (127);      # the entire sequence

    $factorial  = factorial(1000);      # factorial 1000!

    $e = euler(1,64);                   # e to 64 digits

    $b3 = bernoulli(3);

    $cos        = cos(0.5,128);         # cosinus to 128 digits
    $sin        = sin(0.5,128);         # sinus to 128 digits
    $cosh       = cosh(0.5,128);        # cosinus hyperbolicus to 128 digits
    $sinh       = sinh(0.5,128);        # sinus hyperbolicus to 128 digits
    $tan        = tan(0.5,128);         # tangens to 128 digits
    $arctan     = arctan(0.5,64);       # arcus tangens to 64 digits
    $arcsin     = arcsin(0.5,32);       # arcus sinus to 32 digits
    $arcsinh    = arcsin(0.5,18);       # arcus sinus hyperbolicus to 18 digits

    $pi         = pi(1024);             # first 1024 digits
    $log        = log(64,2);            # $log==6, because 2**6==64
    $log        = log(100,10);          # $log==2, because 10**2==100
    $log        = log(100);             # base defaults to 10: $log==2</code></pre>

<h1 id="REQUIRES">REQUIRES</h1>

<p>perl5.006002, Exporter, Math::BigInt, Math::BigFloat</p>

<h1 id="EXPORTS">EXPORTS</h1>

<p>Exports nothing on default, but can export <code>primes()</code>, <code>fibonacci()</code>, <code>hailstone()</code>, <code>bernoulli</code>, <code>euler</code>, <code>sin</code>, <code>cos</code>, <code>tan</code>, <code>cosh</code>, <code>sinh</code>, <code>arctan</code>, <code>arcsin</code>, <code>arcsinh</code>, <code>pi</code>, <code>log</code> and <code>factorial</code>.</p>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This module contains some routines that may come in handy when you want to do some math with really, really big (or small) numbers. These are primarily examples.</p>

<h1 id="FUNCTIONS">FUNCTIONS</h1>

<dl>

<dt id="primes()"><a id="primes"></a>primes()</dt>
<dd>

<pre><code>        @primes = primes($n);
        $primes = primes($n);</code></pre>

<p>Calculates all the primes below N and returns them as array. In scalar context returns the prime count of N (the number of primes less than or equal to N).</p>

<p>This uses an optimized version of the <b>Sieve of Eratosthenes</b>, which takes half of the time and half of the space, but is still O(N).</p>

</dd>
<dt id="fibonacci()"><a id="fibonacci"></a>fibonacci()</dt>
<dd>

<pre><code>        @fib = fibonacci($n);
        $fib = fibonacci($n);</code></pre>

<p>Calculates the first N fibonacci numbers and returns them as array. In scalar context returns the Nth number of the Fibonacci series.</p>

<p>The scalar context version uses an ultra-fast conquer-divide style algorithm to calculate the result and is many times faster than the straightforward way of calculating the linear sum.</p>

</dd>
<dt id="hailstone()"><a id="hailstone"></a>hailstone()</dt>
<dd>

<pre><code>        @hail = hailstone($n);          # sequence
        $hail = hailstone($n);          # length of sequence</code></pre>

<p>Calculates the <i>Hailstone</i> sequence for the number N. This sequence is defined as follows:</p>

<pre><code>        while (N != 0)
          {
          if (N is even)
            {
            N is N /2
            }
          else
            {
            N = N * 3 +1
            }
          }</code></pre>

<p>It is not yet proven whether for every N the sequence reaches 1, but it apparently does so. The number of steps is somewhat chaotically.</p>

</dd>
<dt id="base()"><a id="base"></a>base()</dt>
<dd>

<pre><code>        ($n,$a) = base($number,$base);</code></pre>

<p>Reduces a number to <code>$base</code> to the <code>$n</code>th power plus <code>$a</code>. Example:</p>

<pre><code>        use Math::BigInt :constant;
        use Math::Big qw/base/;

        print base ( 2 ** 150 + 42,2);</code></pre>

<p>This will print 150 and 42.</p>

</dd>
<dt id="to_base()"><a id="to_base"></a>to_base()</dt>
<dd>

<pre><code>        $string = to_base($number,$base);

        $string = to_base($number,$base, $alphabet);</code></pre>

<p>Returns a string of <code>$number</code> in base <code>$base</code>. The alphabet is optional if <code>$base</code> is less or equal than 36. <code>$alphabet</code> is a string.</p>

<p>Examples:</p>

<pre><code>        print to_base(15,2);            # 1111
        print to_base(15,16);           # F
        print to_base(31,16);           # 1F</code></pre>

</dd>
<dt id="factorial()"><a id="factorial"></a>factorial()</dt>
<dd>

<pre><code>        $n = factorial($number);</code></pre>

<p>Calculate <code>n!</code> for <code>n </code>= 0&gt;.</p>

<p>Uses internally Math::BigInt&#39;s bfac() method.</p>

</dd>
<dt id="bernoulli()"><a id="bernoulli"></a>bernoulli()</dt>
<dd>

<pre><code>        $b = bernoulli($n);
        ($c,$d) = bernoulli($n);        # $b = $c/$d</code></pre>

<p>Calculate the Nth number in the <i>Bernoulli</i> series. Only the first 40 are defined for now.</p>

</dd>
<dt id="euler()"><a id="euler"></a>euler()</dt>
<dd>

<pre><code>        $e = euler($x,$d);</code></pre>

<p>Calculate <i>Euler&#39;s constant</i> to the power of $x (usual 1), to $d digits. Defaults to 1 and 42 digits.</p>

</dd>
<dt id="sin()"><a id="sin"></a>sin()</dt>
<dd>

<pre><code>        $sin = sin($x,$d);</code></pre>

<p>Calculate <i>sinus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="cos()"><a id="cos"></a>cos()</dt>
<dd>

<pre><code>        $cos = cos($x,$d);</code></pre>

<p>Calculate <i>cosinus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="tan()"><a id="tan"></a>tan()</dt>
<dd>

<pre><code>        $tan = tan($x,$d);</code></pre>

<p>Calculate <i>tangens</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="arctan()"><a id="arctan"></a>arctan()</dt>
<dd>

<pre><code>        $arctan = arctan($x,$d);</code></pre>

<p>Calculate <i>arcus tangens</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="arctanh()"><a id="arctanh"></a>arctanh()</dt>
<dd>

<pre><code>        $arctanh = arctanh($x,$d);</code></pre>

<p>Calculate <i>arcus tangens hyperbolicus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="arcsin()"><a id="arcsin"></a>arcsin()</dt>
<dd>

<pre><code>        $arcsin = arcsin($x,$d);</code></pre>

<p>Calculate <i>arcus sinus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="arcsinh()"><a id="arcsinh"></a>arcsinh()</dt>
<dd>

<pre><code>        $arcsinh = arcsinh($x,$d);</code></pre>

<p>Calculate <i>arcus sinus hyperbolicus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="cosh()"><a id="cosh"></a>cosh()</dt>
<dd>

<pre><code>        $cosh = cosh($x,$d);</code></pre>

<p>Calculate <i>cosinus hyperbolicus</i> of <code>$x</code>, to <code>$d</code> digits.</p>

</dd>
<dt id="sinh()"><a id="sinh"></a>sinh()</dt>
<dd>

<pre><code>        $sinh = sinh($x,$d);</code></pre>

<p>Calculate <i>sinus hyperbolicus</i> of $&lt;$x&gt;, to <code>$d</code> digits.</p>

</dd>
<dt id="pi()"><a id="pi"></a>pi()</dt>
<dd>

<pre><code>        $pi = pi($N);</code></pre>

<p>The number PI to <code>$N</code> digits after the dot.</p>

</dd>
<dt id="log()"><a id="log"></a>log()</dt>
<dd>

<pre><code>        $log = log($number,$base,$A);</code></pre>

<p>Calculates the logarithmn of <code>$number</code> to base <code>$base</code>, with <code>$A</code> digits accuracy and returns a new number as the result (leaving <code>$number</code> alone).</p>

<p>Math::BigInt objects are promoted to Math::BigFloat objects, meaning you will never get a truncated integer result like when using <code>Math::BigInt-</code>blog()&gt;.</p>

</dd>
</dl>

<h1 id="CAVEATS">CAVEATS</h1>

<ul>

<li><p>Primes and the Fibonacci series use an array of size N and will not be able to calculate big sequences due to memory constraints.</p>

<p>The exception is fibonacci in scalar context, this is able to calculate arbitrarily big numbers in O(N) time:</p>

<pre><code>        use Math::Big;
        use Math::BigInt qw/:constant/;

        $fib = Math::Big::fibonacci( 2 ** 320 );</code></pre>

</li>
<li><p>The Bernoulli numbers are not yet calculated, but looked up in a table, which has only 40 elements. So <code>bernoulli($x)</code> with $x &gt; 42 will fail.</p>

<p>If you know of an algorithmn to calculate them, please drop me a note.</p>

</li>
</ul>

<h1 id="BUGS">BUGS</h1>

<p>Please report any bugs or feature requests to <code>bug-math-big at rt.cpan.org</code>, or through the web interface at <a href="https://rt.cpan.org/Ticket/Create.html?Queue=Math-Big">https://rt.cpan.org/Ticket/Create.html?Queue=Math-Big</a> (requires login). We will be notified, and then you&#39;ll automatically be notified of progress on your bug as I make changes.</p>

<h1 id="SUPPORT">SUPPORT</h1>

<p>You can find documentation for this module with the perldoc command.</p>

<pre><code>    perldoc Math::Big</code></pre>

<p>You can also look for information at:</p>

<ul>

<li><p>GitHub</p>

<p><a href="https://github.com/pjacklam/p5-Math-Big">https://github.com/pjacklam/p5-Math-Big</a></p>

</li>
<li><p>RT: CPAN&#39;s request tracker</p>

<p><a href="https://rt.cpan.org/Dist/Display.html?Name=Math-Big">https://rt.cpan.org/Dist/Display.html?Name=Math-Big</a></p>

</li>
<li><p>MetaCPAN</p>

<p><a href="https://metacpan.org/release/Math-Big">https://metacpan.org/release/Math-Big</a></p>

</li>
<li><p>CPAN Testers Matrix</p>

<p><a href="http://matrix.cpantesters.org/?dist=Math-Big">http://matrix.cpantesters.org/?dist=Math-Big</a></p>

</li>
<li><p>CPAN Ratings</p>

<p><a href="https://cpanratings.perl.org/dist/Math-Big">https://cpanratings.perl.org/dist/Math-Big</a></p>

</li>
</ul>

<h1 id="LICENSE">LICENSE</h1>

<p>This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.</p>

<h1 id="AUTHOR">AUTHOR</h1>

<ul>

<li><p>Tels http://bloodgate.com 2001-2007.</p>

</li>
<li><p>Peter John Acklam &lt;pjacklam@gmail.com&gt; 2016-.</p>

</li>
</ul></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Math::Big, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Math::Big</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Math::Big</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Math::Big.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
